
<template>
    <div class="content-right">
    	<card shadw>
			<Row>
				<Col :xs="15" :sm="15" :md="15" :lg="18">
    		 		{{value}}
    		 	</Col>
    		 	<Col :xs="15" :sm="8" :md="8" :lg="6">
    		 		<router-link :to="{name:'test-particulars',query:{id:examinationRoomId}}"><Button type="primary" icon="chevron-left">返回考试列表</Button></router-link>
    		 		<Button type="primary" @click="spread">试卷浏览</Button>
    		 	</Col>
			</Row>
   			<div class="preciew-test">
	            <div class="test-width">
	               	<h3>{{tileName}}</h3>
	                <p class="test-details">（考试时长：{{duration}}分钟&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;及格分数：{{passScore}}分&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;试题数目：{{totalSubject}}题&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;满分：{{totalPoints}}分）</p>
	                <Table border :columns="columns1" :data="data1" class="title"></Table>
	                <div class="preciew-test-content">
	                    <h4 >一、单选题</h4>
	                    <div v-for="(v,i) in contentBox.radioBox">
	                    	<p>1丶{{v.question}}</p>
	                        <p>考生答案：{{v.eAnswer}}&nbsp;&nbsp;&nbsp;&nbsp;参考答案：{{v.answer}}&nbsp;&nbsp;&nbsp;&nbsp;本题得分：{{(v.eAnswer!=v.answer)?0:v.unitScore}}</p>
	                    </div>
	                    <h4 >二、多选题</h4>
	                    <div v-for="(v,i) in contentBox.checkBox">
	                    	<p>1丶{{v.question}}</p>
 							<p>考生答案：{{v.eAnswer}}&nbsp;&nbsp;&nbsp;&nbsp;参考答案：{{v.answer}}&nbsp;&nbsp;&nbsp;&nbsp;本题得分：{{(v.eAnswer!=v.answer)?0:v.unitScore}}</p>
	                    </div>
	                    <h4 >三、判断题</h4>
	                    <div v-for="(v,i) in contentBox.judgeBox">
	                    	<p>1丶{{v.question}}</p>
							 <p>考生答案：{{v.eAnswer}}&nbsp;&nbsp;&nbsp;&nbsp;参考答案：{{v.answer}}&nbsp;&nbsp;&nbsp;&nbsp;本题得分：{{(v.eAnswer!=v.answer)?0:v.unitScore}}</p>
	                    </div>
	                </div>
	            </div>
    		</div>
    	</card>
    </div>
</template>
<script>
import Cookies from 'js-cookie';
import {router} from "@/router/index.js";
import util from "@/libs/util.js";
export default {
    data() {
        return {
        	data1:[{
        		examineeName:"",
        		idcard:"",
        		eStartTime:"",
        		passScore:"",
        		isQualified:"",
        		oneChoice:0,
        		multipleChoice:0,
        		judge:0,
        		total:0,
        		spendTime:"",
        		unitScore1:"",
        	}],
        	editId:'',
        	examineeId:0,
            name: '',
            duration: '',
            totalPoints: '',
            passScore: '',
            type:'',
            status:'',
            totalPoints:"",
            tileName:"",
            //考场id
            examinationRoomId:0,
            //题目
            subjectArr:[],
        	value:"当前位置：考试中心>考场设置>考卷详情",
        	columns1: [
                {
                    title: '考生姓名',
                    key: 'examineeName'
                },
                {
                    title: '身份证号',
                    key: 'idcard'
                },
                {
                    title: '考试时间',
                    key: 'eStartTime',
                    render:function(h,params){
            			return h('div',
            				util.timestampToTime(params.row.eStartTime)
            		)}
                },
                {
                    title: '考试耗时',
                    key: 'spendTime'
                },
                {
                    title: '考试结果',
                    key: 'isQualified',
                    render:function(h,params){
            			return h('div',
            				params.row.isQualified=params.row.oneChoice+params.row.multipleChoice+params.row.judge>=params.row.passScore?"合格":"不合格"
            		)}
                },
                {
                    title: '单选题',
                    key: 'oneChoice'
                },
                {
                    title: '多选题',
                    key: 'multipleChoice'
                },
                {
                    title: '判断题',
                    key: 'judge'
                },
                {
                    title: '得分',
                    key: 'total'
                }
                
            ],
        }
   },
    created:function(){

		this.editId=this.$route.query.id;
    	var that=this;
    	that.axios({
			method:"get",
			url:that.$store.state.app.globalUrl+"/admin/AcademicRecords/getDetail?id="+that.editId,
			data:{}
		}).then(function(res){
            that.examinationRoomId=res.data.data.academicRecords.examinationRoomId,
            that.data1[0].examineeName=res.data.data.academicRecords.examineeName,
            that.data1[0].idcard=res.data.data.academicRecords.idcard,
            that.data1[0].idceStartTimeard=res.data.data.academicRecords.eStartTime,
            that.data1[0].spendTime=res.data.data.academicRecords.spendTime,
            that.passScore=res.data.data.academicRecords.passScore,
            that.examineeId=res.data.data.academicRecords.examineeId,
            that.totalPoints=res.data.data.academicRecords.totalPoints,
            that.duration=res.data.data.academicRecords.duration,
            that.tileName=res.data.data.academicRecords.testPaperName,
            that.subjectArr=JSON.parse(res.data.data.academicRecords.testPaperDetail),
            that.subjectArr.forEach(function(subjectArr){
            	if(subjectArr.type=='1'){
            		subjectArr.list.forEach(function(v){
            			if(v.eAnswer==v.answer){
            				that.data1[0].oneChoice=that.data1[0].oneChoice+parseInt(subjectArr.unitScore)
            			}
            		})
                }
                if(subjectArr.type=='2'){
                	subjectArr.list.forEach(function(v){
            			if(v.eAnswer==v.answer){
            				that.data1[0].multipleChoice=that.data1[0].multipleChoice+parseInt(subjectArr.unitScore)
            			}
            		})
                }
                if(subjectArr.type=='3'){
                	subjectArr.list.forEach(function(v){
            			if(v.eAnswer==v.answer){
            				that.data1[0].judge=that.data1[0].judge+parseInt(subjectArr.unitScore)
            			}
            		})
                }
            }),
            that.data1[0].total=that.data1[0].oneChoice+that.data1[0].multipleChoice+that.data1[0].judge;
		})
	},
	computed:{
        // 总共的题目
        totalSubject:function(){
            var num=0;
            this.subjectArr.forEach(function(subjectArr){
                num=num+subjectArr.list.length
            })
            return num;
        },
        data2:function(){
            var obj={radio:0,checkbox:0,judge:0,totalScore:this.totalPoints};
            var arr=[obj];
            this.subjectArr.forEach(function(subjectArr){
                if(subjectArr.type=='1'){
                    obj.radio=obj.radio+(subjectArr.list.length*subjectArr.unitScore)
                }
                if(subjectArr.type=='2'){
                    obj.checkbox=obj.checkbox+(subjectArr.list.length*subjectArr.unitScore)
                }
                if(subjectArr.type=='3'){
                    obj.judge=obj.judge+(subjectArr.list.length*subjectArr.unitScore)
                }
            })
           return arr;
        },
       contentBox:function(){
          var objBox={radioBox:[],checkBox:[],judgeBox:[]};
           this.subjectArr.forEach(function(subjectArr){
                if(subjectArr.type=='1'){
                    objBox.radioBox=objBox.radioBox.concat(subjectArr.list)
                    objBox.radioBox.forEach(function(v){
                    	v['unitScore']=subjectArr.unitScore
                    })
                }
                if(subjectArr.type=='2'){
                    objBox.checkBox=objBox.checkBox.concat(subjectArr.list)
                    objBox.checkBox.forEach(function(v){
                    	v['unitScore']=subjectArr.unitScore
                    })
                }
                if(subjectArr.type=='3'){
                    objBox.judgeBox=objBox.judgeBox.concat(subjectArr.list)
                    objBox.judgeBox.forEach(function(v){
                    	v['unitScore']=subjectArr.unitScore
                    })
                }

            })
           return objBox;
       } 
    },
	methods:{
		spread:function(){
			router.push({
				name:"paper-browse",
				query:{
					id:this.editId,
				}
			})
		}
	}
};
</script>
<style scoped>
.title{text-align: center;margin-top:10px;}
.preciew-test h3{text-align: center;}
.preciew-test p.test-details{text-align: center;margin-top:20px;margin-bottom: 40px }
.preciew-test .preciew-test-content{margin-top: 50px}
.preciew-test-content h4{margin-top: 20px;font-size: 16px}
.preciew-test-content div{margin-top: 20px}
.preciew-test-content div strong{font-weight: 700;}
.preciew-test-content p{margin-left: 20px}
</style>